<template>
	<view>
		<view style="height: 320rpx;" class="w-100 d-flex j-center a-center position-relative">
			<image src="/static/mine-bg.png" class="position-absolute left-0 right-0 top-0 bottom-0 w-100 h-100"
				style="opacity: 0.5;" />
			<view>
				<view style="width: 300rpx; z-index: 100;" class="d-flex flex-column a-center">
					<image :src="avatar" style="width: 100rpx; height: 100rpx; object-fit: cover;"
						class="rounded-circle" />
					<view class="font text-white mt-3" style="z-index: 101;">{{username}}</view>
				</view>
			</view>
		</view>
		<uni-list>
			<uni-list-item showArrow title="修改信息" style="margin-bottom: 10rpx;" to="/pages/userinfo/userinfo"></uni-list-item>
			<uni-list-item showArrow title="我的地址" style="margin-bottom: 10rpx;" to="/pages/address/address"></uni-list-item>
		</uni-list>
		<button @click="onExit" type="warn" plain="false" class="mt-2" style="width: 100%; padding: 10rpx;" >退出登录</button>

	</view>
</template>

<script setup>
import userHttp from '../../apis/user/userHttp'
import {onShow} from "@dcloudio/uni-app"
import useAuthStore from '../../stores/auth'
const authStore = useAuthStore()
const avatar = authStore.user.avatar
const username = authStore.user.username
onShow(() => {
  if(!authStore.is_logined){
    uni.redirectTo({
      url: "/pages/login/login"
    })
  }
})
const onExit = async () => {
  // 1. 发起请求，告诉服务器退出登录
  await userHttp.logout()
  // 2.清除本地数据
  authStore.clearUserToken();
  uni.switchTab({
    url: "/pages/index/index"
  })
}
</script>

<style></style>
